新手问题 - 正斜杠和反斜杠 grr
我正在使用cakephp。在我的用户模型中,我允许 ppl 上传图片。上传成功后,我将图片的 url 保存到 $this->data['User']['image_url']
并保存。要上传,我使用此处给出的建议: http://www.jamesfairhurst.co.uk /posts/view/uploading_files_and_images_with_cakephp
上传完成后,我想调整照片大小,以便有缩略图。我在这里使用建议: http://bakery .cakephp.org/articles/Perkster/2008/04/12/image-resizer-crop
一切都可以,除了中的值$this->data['User']['image_url']
看起来像 files/photos/userimage.jpg
我正在使用的上传脚本似乎符合预期带有反斜杠而不是正斜杠的网址,因为当我运行它时,我收到错误
getimagesize(C:\xampp\htdocs\MyNewSite\app\webroot\img\files/photos\$image_name) [function.getimagesize]: failed to open stream:
我能做些什么来解决这个问题?
I'm using cakephp. In my users model I allow ppl to upload a pic. Once it uploads ok I save the url of the pic to $this->data['User']['image_url']
and save it. To upload I use the kind advice given here: http://www.jamesfairhurst.co.uk/posts/view/uploading_files_and_images_with_cakephp
After the upload is done I want to resize the photo so I have a thumbnail. I'm using the advice here: http://bakery.cakephp.org/articles/Perkster/2008/04/12/image-resizer-crop
All is ok, except for the value in $this->data['User']['image_url']
looks like files/photos/userimage.jpg
The upload script I'm using seems to be expecting the urls with backslashes rather than forward ones coz when I run it I get the error
getimagesize(C:\xampp\htdocs\MyNewSite\app\webroot\img\files/photos\$image_name) [function.getimagesize]: failed to open stream:
What can I do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
斜杠不是问题,
$image_name
才是。如果不看代码就不可能知道,但您在分配文件名时可能使用单引号,导致变量无法正确解析。The slashes are not the problem, the
$image_name
is. It's impossible to tell without seeing the code, but you probably are using single quotes when assigning the file name, leading to the variable not getting parsed properly.Windows 接受目录分隔符
\
和/
,因此问题一定出在其他地方。这是从我假设的错误消息中获取的,没有文件
$image_name
;) 看来,您在调用getimagesize()
时没有让 PHP 评估变量Windows accepts both directory separators
\
and/
, thus the problem must be somewhere else. This is taken from the error messageI assume, that there is no file
$image_name
;) It seems, that you didnt let PHP evaluate the variables when callinggetimagesize()